home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 55 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.4 KB

  1. Path: fido.asd.sgi.com!austern
  2. From: "Eugene Radchenko" <eugene@qsar.chem.msu.su>
  3. Newsgroups: comp.std.c++
  4. Subject: More on the operations on the entire container
  5. Date: 17 Jan 1996 12:21:55 PST
  6. Organization: Lab. of Org.Synth., MSU
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <AFyED_m0h3@qsar.chem.msu.su>
  9. NNTP-Posting-Host: isolde.mti.sgi.com
  10. X-Original-Date: Wed, 17 Jan 1996 13:47:24 +0300 (MSK)
  11. X-Mailer: dMail [Demos Mail for DOS v1.23]
  12. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  13.     iQBVAwUBMP1adky4NqrwXLNJAQGrAAIAknlh0cL24IH/hR05SwFskqyRs/BsAw/p
  14.     xxJLM3ms7zFt/o+OV4JI4q6EsPEBmu7N/rMZN4sG4qoXogj6QYoNsg==
  15.     =kMyz
  16. Originator: austern@isolde.mti.sgi.com
  17.  
  18. Hi!
  19. Operations on the whole container are (as the threads flashing here
  20. sometimes show) the most common kind of range operations in a program using
  21. the STL. Hence, it is generally felt that the current idiom for this
  22.   Iterator i = find(c.begin(), c.end(), x);
  23. is verbose, cumbersome and error-prone. However, no solution (fitting into
  24. the split container/algorithm paradigm) has been proposed yet.
  25. I think this can do the trick:
  26.   template <class Iterator> struct range : public pair<Iterator, Iterator> {
  27.    range(Iterator first, Iterator last)
  28.       : pair<Iterator, Iterator>(first, last) {}
  29.   };
  30.   template <...> class vector  {
  31.     //....
  32.     range<iterator> all()  { return range(begin(), end()); }
  33.     range<const_iterator> all() const { return range(begin(), end()); }
  34.   };
  35. Also, the library would provide the 'range' version of all functions, e.g.
  36.   template<class Iterator, class T> Iterator find(range<Iterator> r, T x);
  37. simply inlining to find(r.first, r.second, x).
  38.  
  39. (If the conversions were allowed in the template deduction, it would be
  40. even simpler with
  41.    operator range<iterator>()
  42. in vector).
  43.  
  44.      So, what do you think?                            Genie
  45.  
  46. --
  47. --------------------------------------------------------------------
  48. Eugene V. Radchenko           Research associate, Computer Chemistry
  49. E-mail: eugene@qsar.chem.msu.su                Fax: +7-(095)939-0290 
  50. Ordinary mail:  Chair of Organic Chemistry, Department of Chemistry,
  51.                       Moscow State University, 119899 Moscow, Russia
  52. *****************  Disappearances are deceptive  *******************
  53. ---
  54. [ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  55.   Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  56.   is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
  57.